# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=portia
pkgver=39.2e6e608
pkgrel=5
pkgdesc='Automate a number of techniques commonly performed on internal network penetration tests after a low privileged account has been compromised.'
groups=('blackarch' 'blackarch-automation')
arch=('any')
url='https://github.com/SpiderLabs/portia'
license=('Apache')
depends=('python2' 'python2-pyasn1' 'python2-pymysql' 'python2-argparse'
         'python2-tabulate' 'python2-termcolor' 'python2-python-nmap'
         'python2-netaddr' 'python2-dnspython' 'python2-impacket' 'volatility3'
         'python2-xmltodict' 'python2-pysmb' 'ntdsxtract' 'pymssql'
         'python2-pyopenssl' 'python2-setuptools')
makedepends=('git')
source=("git+https://github.com/SpiderLabs/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

build() {
  cd $pkgname

  git clone https://github.com/CoreSecurity/impacket
  git clone https://github.com/libyal/libesedb.git && cd libesedb
  ./synclibs.sh
  ./autogen.sh

  cd ../ && git submodule init && git submodule update --recursive
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.md
  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  rm README.md LICENSE

  mv impacket/* "$pkgdir/usr/share/$pkgname"

  rm -rf impacket

  cp -a * "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python2 $pkgname.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

